﻿using System;
using System.Collections.Generic;

namespace SoftwareLogistics.SharepointClient.Library.Models
{
    public class ListFilters
    {
        public static Dictionary<string, List<SPQuery>> GetFilters()
        {
            var filters = new Dictionary<string, List<SPQuery>>();

            var newTasks = new SPQuery() { Name = "New Tasks" };
            newTasks.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "Status", "New");

            var taskQuery = new SPQuery() { Name = "My Open Tasks", IsDefault = true };
            taskQuery.AddAndClause(SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "AssignedTo", Common.Users.CurrentUser),
                SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "Status", "In Progress"));

            var allMyTasks = new SPQuery() { Name = "All My Tasks" };
            allMyTasks.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "AssignedTo", Common.Users.CurrentUser);

            var allActiveTasks = new SPQuery() { Name = "All Active Tasks" };
            allActiveTasks.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "Status", "In Progress");



            filters.Add("Tasks", new List<SPQuery>() { new SPQuery() { Name = "All" }, newTasks, allActiveTasks, allMyTasks, taskQuery });

            var activeProjects = new SPQuery() { Name = "Active Projects", IsDefault = true };
            activeProjects.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "Status", "Implementation");

            var pendingProjects = new SPQuery() { Name = "Pending Projects" };
            pendingProjects.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "Status", "Pending");

            filters.Add("Project", new List<SPQuery> { new SPQuery() { Name = "All" }, activeProjects, pendingProjects });
            
            var myTimeRecords = new SPQuery() { Name = "My Time Records", IsDefault = true };
            myTimeRecords.WhereClause = SPWhereClause.Create(SPWhereClause.ComparisonTypes.Equal, "User", Common.Users.CurrentUser);            

            /* TODO: Failed attempt at doing a join/aggregate someone wanna fix?
             * var timePerTask = new SPQuery() { Name = "Time per Task" };
            timePerTask.AddJoin("Tasks", "Task");
            timePerTask.AddProjectedField("Project", "Tasks", "ProjectName");
            timePerTask.AddProjectedField("Title", "Tasks", "TaskName");
            timePerTask.AddProjectedField("Title", "Time", "Activity");
            timePerTask.AddProjectedField("Hours Worked", "Time", "HoursWorked");*/


            filters.Add("Time", new List<SPQuery> { new SPQuery() { Name = "All" }, myTimeRecords }); /*, timePerTask });*/
            

            return filters;
        }
    }
}
